package lesson04;

import java.util.*;

public class TestMain8 {
    public static void main(String[] args) {
        // k  ,  V
        // 100010  东城区    一个kv就是一个entry
        // 116021  沙河口区
        // 116022  高新区
        // 116023  高新区
        // 116023  中山区
        Map<String, String> map = new HashMap<>();
        map.put("116022", "高新区");
        map.put("116021", "沙河口区");
        map.put("116023", "高新区");
        map.put("116023", "中山区"); // key唯一  value覆盖

        System.out.println(map.size());
        System.out.println(map.get("116023"));

        map.forEach((k, v) -> {
            System.out.println(k + "@" + v);
        });
        System.out.println("--------------------");
        Map<Student, String> map1 = new HashMap<>();
        map1.put(new Student("tom", 1), "jklajflasjdl");
        map1.put(new Student("tom", 1), "jklajflasjdl");
        map1.put(new Student("tom", 2), "jklajflasjdl");
        System.out.println(map1.size());
        // keySet遍历
        Set<Student> keys = map1.keySet();
        keys.forEach(System.out::println);

        System.out.println("--------------------");
        Map<Student, String> map222 = new TreeMap<>();
        map222.put(new Student("tom", 3), "jklajflasjdl");
        map222.put(new Student("tom", 1), "jklajflasjdl");
        map222.put(new Student("tom", 4), "jklajflasjdl");
        map222.put(new Student("tom", 1), "aaa");
        map222.put(new Student("tom", 2), "jklajflasjdl");
        System.out.println(map222.size());
        // entryset遍历
        Set<Map.Entry<Student, String>> es = map222.entrySet();
        es.forEach((item) -> { // entry k,v
            System.out.println(item.getKey() + "@" + item.getValue());
        });
    }
}
